//
//  Convenience.m
//  NBTripe
//
//  Created by Lee on 16/1/11.
//  Copyright © 2016年 Vicki. All rights reserved.
//

#import "Convenience.h"

@implementation Convenience

+ (void)createLabel:(UILabel *)label WithFrame:(CGRect )frame FrameWithTextColor:(UIColor *)textcolor TextColorWithFont:(UIFont *)font FontWithNSTextAlignment:(NSTextAlignment)textalignment TextAlignmentWithNumberOfLines:(NSInteger)NumberOfLines WithText:(NSString *)text {
    label.frame = frame;
    label.textColor = textcolor;
    label.font = font;
    label.textAlignment = textalignment;
    label.numberOfLines = NumberOfLines;
    label.text = text;
}

+ (void)createCellLabel:(UILabel *)label LabelWithTextColor:(UIColor *)textcolor TextColorWithFont:(UIFont *)font FontWithNSTextAlignment:(NSTextAlignment)textalignment TextAlignmentWithNumberOfLines:(NSInteger)NumberOfLines {
    label.textColor = textcolor;
    label.font = font;
    label.textAlignment = textalignment;
    label.numberOfLines = NumberOfLines;
}
+ (void)createCirCleImageView:(UIImageView *)imageview WithFrame:(CGRect )frame WithCorNerRadius:(NSInteger )radius{
    imageview.frame = frame;
    imageview.layer.masksToBounds = YES;
    imageview.layer.cornerRadius = radius;
}
+ (NSArray *)selectLocalCoreDataWithManager:(CoreDataManager *)manager {
    //发起一个数据请求
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    //实体描述
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Storage" inManagedObjectContext:manager.managedObjectContext];
    [fetchRequest setEntity:entity];
    //    // Specify criteria for filtering which objects to fetch
    //    谓词，查询条件
    //    使用and和or进行多条件查询
//    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name = %@", @"硕大的"];
  //  [fetchRequest setPredicate:predicate];
    //    // Specify how the fetched objects should be sorted
    //    排序，yes代表升序，no代表降序
//    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"age"
//                                                                   ascending:NO];
//    [fetchRequest setSortDescriptors:[NSArray arrayWithObjects:sortDescriptor, nil]];
    
    NSError *error = nil;
    NSArray *result = [NSArray array];
    result = [manager.managedObjectContext executeFetchRequest:fetchRequest error:&error];
    if (result == nil) {
        NSLog(@"%@", error);
    }
//    for (Storage *stu in result) {
//        NSLog(@"%@,%@", stu.photo, stu.title);
//    }
    return result;
    
}

+ (NSArray *)selectLocalCorearr:(CoreDataManager *)manager managerWithstr:(NSString *)str {
    //发起一个数据请求
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    //实体描述
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Storage" inManagedObjectContext:manager.managedObjectContext];
    [fetchRequest setEntity:entity];
    //    // Specify criteria for filtering which objects to fetch
    //    谓词，查询条件
    //    使用and和or进行多条件查询
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"joinid = %@", str];
      [fetchRequest setPredicate:predicate];
    //    // Specify how the fetched objects should be sorted
    //    排序，yes代表升序，no代表降序
    //    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"age"
    //                                                                   ascending:NO];
    //    [fetchRequest setSortDescriptors:[NSArray arrayWithObjects:sortDescriptor, nil]];
    
    NSError *error = nil;
    NSArray *result = [NSArray array];
    result = [manager.managedObjectContext executeFetchRequest:fetchRequest error:&error];
    if (result == nil) {
        NSLog(@"%@", error);
    }
    //    for (Storage *stu in result) {
    //        NSLog(@"%@,%@", stu.photo, stu.title);
    //    }
    return result;
    
}

+ (NSString *)selectIdentifierWithManager:(CoreDataManager *)manager managerWithStr:(NSString *)str {
    //发起一个数据请求
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    //实体描述
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Storage" inManagedObjectContext:manager.managedObjectContext];
    [fetchRequest setEntity:entity];
    
    NSError *error = nil;
    NSArray *result = [NSArray array];
    result = [manager.managedObjectContext executeFetchRequest:fetchRequest error:&error];
   // NSLog(@"%ld", result.count);
    if (result == nil) {
        NSLog(@"%@", error);
    }
    
    //如果存在相同的,则表示已经收藏
    for (Storage *s in result) {
       // NSLog(@"111111===========%@", s.joinid);
      //  NSLog(@"+++++++++_______%@",str);
        if ([s.joinid isEqualToString: str]) {
//            NSLog(@"%@----%@", s.joinid, str);
            
            return str;
        }
    }
    //如果没有相同的，则表示未收藏过
    return nil;
    
}





@end
